package com.guanyong.webapi.controllers.api;

import com.guanyong.model.FilmModel;
import com.guanyong.model.FilmTypeModel;
import com.guanyong.services.FilmTypeService;
import com.guanyong.utils.Cache.ICahce.ICache;
import com.guanyong.utils.Comm.ResultObject;
import net.sf.ehcache.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mxk on 2017/9/19.
 */
@RestController
@RequestMapping("/api/filmtype/")
public class FilmTypeApi {

    @Autowired
    ICache cache;

    @Value("${video.type.cache}")
    String videoTypeCache;
    @Autowired
    private FilmTypeService filmTypeService;

    @RequestMapping(value = "getfilmtypelist", method = RequestMethod.GET)
    public ResultObject<List<FilmTypeModel>> GetFilmTypeList(){
        ResultObject<List<FilmTypeModel>> resultObject=new ResultObject<List<FilmTypeModel>>();
            List<FilmTypeModel> filmTypeModels=filmTypeService.GetInstance();

        resultObject.setResult(filmTypeModels);
        return resultObject;
    }

    @RequestMapping(value = "getfilmtypelist1_0", method = RequestMethod.GET)
    public ResultObject<List<FilmTypeModel>> GetFilmTypeList1_0(){
        ResultObject<List<FilmTypeModel>> resultObject=new ResultObject<List<FilmTypeModel>>();
        List<FilmTypeModel> filmTypeModels=filmTypeService.GetInstance2();
        resultObject.setResult(filmTypeModels);
        return resultObject;
    }


    @RequestMapping(value = "getvideotypeall", method = RequestMethod.GET)
    public ResultObject<Map<String,String>> getVideoTypeAll(){
        ResultObject<Map<String,String>> resultObject=new ResultObject<Map<String,String>>();

        Map<String,String> map=new HashMap<String, String>();
        for (Map.Entry<String, Object> entry : cache.get(videoTypeCache).entrySet()) {
            Element element= (Element)entry.getValue();
            map.put(entry.getKey(),(String) element.getObjectValue());
        }
        resultObject.setResult(map);
        return  resultObject;
    }
}
